package com.yzyz.web.controller.visitor;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.yzyz.bean.route.RouteBean;
import com.yzyz.bean.scenic.PictureBean;
import com.yzyz.bean.scenic.ScenicBean;
import com.yzyz.data.CacheFactory;
import com.yzyz.utils.ValidateUtils;

/**
 * 
 * @author David Sun
 * @Date   2010-4-11
 *
 */
public class ScenicController extends MultiActionController {
	
	/**
	 * 通过景区名字来查看景区信息
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ModelAndView getInfoByName(HttpServletRequest request, HttpServletResponse response) throws IOException{
		String name = request.getParameter("scenicName");
		if(ValidateUtils.isNull(name)){
			response.sendError(HttpServletResponse.SC_FORBIDDEN);
			return null;
		}
		ScenicBean scenic = CacheFactory.getRegionStore().searchScenicByName(name.trim());
		if(scenic == null){
			ModelAndView mv = new ModelAndView("/Error/error.jsp");
			mv.addObject("errorMsg", "对不起没有找到  " + name + " 景区的相关信息");
			return mv;
		}
		List<RouteBean> routes = scenic.getRoutes();
		List<PictureBean> pictures = scenic.getPictures();
		ModelAndView mv = new ModelAndView("/Scenic/scenicInfo.jsp");
		mv.addObject("pictures", pictures);
		mv.addObject("scenic", scenic);
		mv.addObject("routes", routes);
		return mv;
	}

	public ModelAndView getInfoById(HttpServletRequest request, HttpServletResponse response) throws IOException{
		ScenicBean scenic = CacheFactory.getRegionStore().getScenicById(Integer.valueOf(request.getParameter("scenicId")));
		if(scenic == null){
			ModelAndView mv = new ModelAndView("/Error/error.jsp");
			mv.addObject("errorMsg", "对不起！没有找到您查看的 景区的相关信息");
			return mv;
		}
		List<RouteBean> routes 		= scenic.getRoutes();
		List<PictureBean> pictures 	= scenic.getPictures();
		ModelAndView mv = new ModelAndView("/Scenic/scenicInfo.jsp");
		mv.addObject("pictures", pictures);
		mv.addObject("scenic", scenic);
		mv.addObject("routes", routes);
		return mv;
		
	}
}
